package com.sh4.controller;


import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.sh4.entity.SystemEnum;
import com.sh4.entity.User;
import com.sh4.service.EnumService;

import net.sf.json.JSONObject;

@RestController
@RequestMapping(value="enum")
public class EnumController {

	@Autowired
	EnumService enumService;
	
	
	@RequestMapping(value="/list",method=RequestMethod.POST)
	public Map<String , Object> getList(@RequestBody JSONObject params, @RequestParam int pageSize , @RequestParam int pageNo){
		
		return enumService.list(pageNo, pageSize, params);
	}
	
	@RequestMapping(value="/",method=RequestMethod.POST)
	public SystemEnum saveEnum(@RequestBody SystemEnum e) {
		
		enumService.saveEnum(e);
		
		return e;
	}
	
	@RequestMapping(value="/",method=RequestMethod.DELETE)
	public SystemEnum deleteEnum(@RequestBody SystemEnum e) {
		
		enumService.deleteEnum(e);
		
		return e;
	}
	
	@RequestMapping(value = "enumList" , method = RequestMethod.POST)
	public Map<String , Object> getEnumList(@RequestBody JSONObject reqBody){
		
		Map<String, Object> result = new HashMap<String,Object>();
		int status = 200;
		String msg = "请求成功";
		
		try {
			
			result.put("dataList", enumService.getEnumList(reqBody.getString("parentCode")));
			
		} catch (Exception e) {
			status = 300;
			msg = "内部错误";
		}
		result.put("status", status);
		result.put("msg", msg);
		
		return result;
	}
}
